package com.download.zhuaba.Controller;

import com.alibaba.fastjson.JSON;
import com.download.zhuaba.Entity.Video;
import com.download.zhuaba.Service.NewsService;
import com.download.zhuaba.Service.VideoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller
public class VideoController {
    @GetMapping("/Video.html")
    public String video(Model model, HttpServletRequest request, HttpSession session){
        if(request.getSession().getAttribute("loginUser")!=null){
            ArrayList<Video> videos = VideoService.getHtml();
            String jsonList = JSON.toJSONString(videos);
            session.setAttribute("flag", "1");//跳转地址不带上u2参数
            session.setAttribute("login","1");
            model.addAttribute("htmlCode2",jsonList);
            return "Video";
        }
        else{
            session.setAttribute("flag", "1");//跳转地址不带上u2参数
            session.setAttribute("login","0");
            return "login";
        }
    }
}
